
//当前开发工程（node代理请求后台地址）系统url(开发必配置)

const proxyUrl = {
    afsContract: 'http://127.0.0.1:9999',
    afsApply: 'http://127.0.0.1:9999',
    afsChannel: 'http://127.0.0.1:9999',
    afsCoreBusiness: 'http://127.0.0.1:9999',
    afsWorkflow: 'http://127.0.0.1:9999',
}
let projectInfo ={name: process.argv[4]}

//当前开发工程，后台代理地址(开发需访问后台必配置)
let projectsProxies = {
    afsContract: {
        proxyInfo: {//代理信息配置
            '/contractManage': {
                target: proxyUrl[projectInfo.name],
                ws: true,
                pathRewrite: {
                    '^/contractManage': '/contractManage'
                },
                //开发机器请求转发地址
                // onProxyReq: function (proxyReq,req, res) {
                //     proxyReq.setHeader('dev_host', '10.50.136.62:6004')
                // },
            },
            '/contractBasic': {
                target: proxyUrl[projectInfo.name],
                ws: true,
                pathRewrite: {
                    '^/contractBasic': '/contractBasic'
                },
                //开发机器请求转发地址
                // onProxyReq: function (proxyReq,req, res) {
                //     proxyReq.setHeader('dev_host', '10.50.136.62:6002')
                // }
            },
            '/contractFinance': {
                target: proxyUrl[projectInfo.name],
                ws: true,
                pathRewrite: {
                    '^/contractFinance': '/contractFinance'
                },
                //开发机器请求转发地址
                // onProxyReq: function (proxyReq,req, res) {
                //     proxyReq.setHeader('dev_host', '10.50.136.62:6003')
                // }
            },
            '/contractAccount': {
                target: proxyUrl[projectInfo.name],
                ws: true,
                pathRewrite: {
                    '^/contractAccount': '/contractAccount'
                },
                //开发机器请求转发地址
                // onProxyReq: function (proxyReq,req, res) {
                //     proxyReq.setHeader('dev_host', '10.50.136.62:6001')
                // }
            },
            '/contractGateway': {
                target: proxyUrl[projectInfo.name],
                ws: true,
                pathRewrite: {
                    '^/contractGateway': '/contractGateway'
                },
                //开发机器请求转发地址
                // onProxyReq: function (proxyReq,req, res) {
                //     proxyReq.setHeader('dev_host', '10.50.136.62:6001')
                // }
            },
        }
    },
    afsApply: {
        proxyInfo: {//代理信息配置
            '/apply': {
                target: proxyUrl[projectInfo.name],
                ws: true,
                pathRewrite: {
                    '^/apply': '/apply'
                }
            },
            '/image': {
                target: proxyUrl[projectInfo.name],
                ws: true,
                pathRewrite: {
                    '^/image': '/image'
                }
            },
        }
    },
    afsCoreBusiness: {
        proxyInfo: {//代理信息配置
            '/case': {
                target: proxyUrl[projectInfo.name],
                ws: true,
                pathRewrite: {
                    '^/case': '/case'
                }
            },
            '/product': {
                target: proxyUrl[projectInfo.name],
                ws: true,
                pathRewrite: {
                    '^/product': '/product'
                }
            },
            '/image': {
                target: proxyUrl[projectInfo.name],
                ws: true,
                pathRewrite: {
                    '^/image': '/image'
                }
            },
        }
    },
    afsChannel: {
        proxyInfo: {//代理信息配置
            '/channel': {
                target: proxyUrl[projectInfo.name],
                ws: true,
                pathRewrite: {
                    '^/channel': '/channel'
                }
            },
            '/workflow': {
                target: proxyUrl[projectInfo.name],
                ws: true,
                pathRewrite: {
                    '^/workflow': '/workflow'
                }
            },
            '/image': {
                target: proxyUrl[projectInfo.name],
                ws: true,
                pathRewrite: {
                    '^/image': '/image'
                }
            },
        }
    },
    afsWorkflow: {
        proxyInfo: {//代理信息配置
            '/workflow': {
                target: proxyUrl[projectInfo.name],
                ws: true,
                pathRewrite: {
                    '^/workflow': '/workflow'
                }
            },
        }
    },
}

const COMMON_PROXY = {
    '/auth': {
        target: proxyUrl[projectInfo.name],
        ws: true,
        pathRewrite: {
            '^/auth': '/auth'
        }
    },
    '/userlogin': {
        target: proxyUrl[projectInfo.name],
        ws: true,
        pathRewrite: {
            '^/userlogin': '/userlogin'
        }
    },
    '/pubkey': {
        target: proxyUrl[projectInfo.name],
        ws: true,
        pathRewrite: {
            '^/pubkey': '/pubkey'
        }
    },
    '/refreshtoken': {
        target: proxyUrl[projectInfo.name],
        ws: true,
        pathRewrite: {
            '^/refreshtoken': '/refreshtoken'
        }
    },
    '/admin': {
        target: proxyUrl[projectInfo.name],
        ws: true,
        pathRewrite: {
            '^/admin': '/admin'
        }
    },
    '/filecenter': {
        target: proxyUrl[projectInfo.name],
        ws: true,
        pathRewrite: {
            '^/filecenter': '/filecenter'
        }
    },
    '/captcha': {
        target: proxyUrl[projectInfo.name],
        ws: true,
        pathRewrite: {
            '^/captcha': '/captcha'
        }
    },
    '/workflow': {
        target: proxyUrl[projectInfo.name],
        ws: true,
        pathRewrite: {
            '^/workflow': '/workflow'
        }
    },
    '/jobadmin': {
        target: proxyUrl[projectInfo.name],
        ws: true,
        pathRewrite: {
            '^/jobadmin': '/jobadmin'
        }
    },
    '/demo': {
        target: proxyUrl[projectInfo.name],
        ws: true,
        pathRewrite: {
            '^/demo': '/demo'
        }
    },
    '/foo': {
        target: '<other_url>'
    }
}

const afs_proxy_config = {
    getProjectInfo: () => {
        return projectInfo;
    },
    getProxyInfo: () => {
        return {
            ...COMMON_PROXY,
            ...projectsProxies[projectInfo.name].proxyInfo
        }
    }
}
module.exports = afs_proxy_config;
